<template>
  <div class="history-warp">
    <h2>历史纪录配置</h2>
    <el-form :rules="rules" :model="ruleForm" ref="ruleForm" label-width="220px">
      <el-form-item label="测试工具历史纪录保留时长(天)" prop="recordTime">
        <el-input  size="small" v-model="ruleForm.recordTime" style="width: 300px" placeholder="1-99" max="99" min="1"></el-input>
      </el-form-item>
      <el-form-item>
        <el-button type="primary" size="small" @click="submitForm()">保存</el-button>
      </el-form-item>
    </el-form>
  </div>
</template>

<script>
  export default {
    name: "History",
    data() {
      return {
        ruleForm: {
          recordTime: '',
        },
        rules: {
          recordTime: [
            {required: true, message: '请输入测试工具历史纪录保留时长', trigger: 'blur'},
            { pattern: /^([1-9]\d?|99)$/, message: '输入值为(1-99)，不允许输入空格等特殊符号' },
          ]
        }
      };
    },
    created() {
      this.axios.get('/api/config').then(res => {
        this.ruleForm.recordTime = res.data.data.recordTime;
      })
    },
    methods: {
      submitForm() {
        this.$refs["ruleForm"].validate((valid) => {
          if (valid) {
            this.axios.post('/api/config', {
              recordTime: this.ruleForm.recordTime,
              id: 1
            }).then(res => {
              this.$notify.success('保存成功')
            })
          }
        });
      }
    }
  }
</script>

<style scoped lang="less">
  .history-warp {
    box-sizing: border-box;
    height: 100%;
    border: 20px solid #e2eaed;
    padding-top: 15px;
    h2 {
      margin-bottom: 15px;
      margin-left: 14px;
    }
  }
</style>
